import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  css: ['@/assets/fonts/fonts.css'],
  runtimeConfig: {
    // 通用配置，在服务端和客户端都可以使用
    public: {
      // 默认请求路径
      baseURL: process.env.NUXT_BASE_URL || 'http://localhost:8787',
      proxyURL: process.env.NUXT_PROXY_URL
    }
  },
  devtools: { enabled: true },
  build: {
    transpile:
      process.env.NODE_ENV === 'production'
        ? ['naive-ui', 'vueuc', '@css-render/vue3-ssr', 'juggle/resize-observer']
        : ['@juggle/resize-observer']
  },
  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "@/assets/scss/main.scss" as *;'
        }
      }
    },
    optimizeDeps: {
      include:
        process.env.NODE_ENV === 'development'
          ? ['naive-ui', 'vueuc', 'date-fns-tz/esm/formatInTimeZone']
          : []
    },
    plugins: [
      AutoImport({
        imports: [
          {
            'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
          }
        ]
      }),
      Components({
        resolvers: [NaiveUiResolver()]
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'assets/svg')],
        symbolId: 'icon-[dir]-[name]'
      })
    ]
  },
  modules: ['@pinia/nuxt', '@vueuse/nuxt'],
  // 跨域处理
  nitro: {
    devProxy: {
      '/api': {
        target: process.env.NUXT_BASE_URL,
        changeOrigin: true
        // prependPath: true,
      }
    }
  }
})
